﻿using System;
using System.Collections.Generic;
using TFile.CES.Entidades;
using TFile.CES.Repositorios;

namespace TFile.CAD.Repositorios
{
    public class BaseRepositorio<T> : IRepositorio<T> where T : IEntidade
    {
        

        public BaseRepositorio()
        {
        }

        public T Retorna(long id)
        {
            //using (ISession _session = NHibernateHelper.OpenSession())
            //{
            //return _session.Get<T>(id);
            return (T)(new Object());
            //}
        }

        public IList<T> RetornaTodos()
        {
            //using (ISession _session = NHibernateHelper.OpenSession())
            //{
            //return _session.CreateCriteria(typeof(T)).List<T>();
            //}
            return new List<T>();
        }

        public T Salva(T entity)
        {
            //using (ISession _session = new NHibernateHelper(_user.Id).OpenSession())
            //AuditLogInterceptor interceptor = new AuditLogInterceptor();
            //using (ISession _session = NHibernateHelper.OpenSession(interceptor))            
            //{
            //interceptor.UserId = _user.Id;
            //interceptor.Session = _session;
            //ITransaction transaction = _session.BeginTransaction();
            //T nentity = (T)_session.Merge(entity);
            //transaction.Commit();

            //using (ITransaction transaction = _session.BeginTransaction())
            //{
            //_session.SaveOrUpdate(entity);            

            //_session.Evict(entity);
            //_session.Refresh(entity);
            //T rentity = (T)_session.Get(typeof(T), Id); 
            //_session.Refresh(entity);
            //}
            //}
            return entity;
        }

        public void Exclui(T entity)
        {
            //using (ISession _session = new NHibernateHelper(_user.Id).OpenSession())
            //AuditLogInterceptor interceptor = new AuditLogInterceptor();
            //using (ISession _session = NHibernateHelper.OpenSession(interceptor))
            //{
            //interceptor.UserId = _user.Id;
            //interceptor.Session = _session;
            //using (ITransaction transaction = _session.BeginTransaction())
            //{
            //    _session.Delete(entity);
            //    transaction.Commit();
            //}
            //}
        }
    }
}
